
package com.tianpengtech.common.pay.weixin.config;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import com.tianpengtech.common.pay.weixin.required.IWXPayDomain;
import com.tianpengtech.common.pay.weixin.required.WXPayDomainSimpleImpl;

public class WXPayConfigImpl extends WXPayConfig{

    private byte[] certData;
    private static WXPayConfigImpl INSTANCE;

    /**
     * 假如需要证书，请将证书路径配置好
     * @throws Exception
     */
    public WXPayConfigImpl() throws Exception{
//        String certPath = "D://CERT/common/apiclient_cert.p12";
//        File file = new File(certPath);
//        InputStream certStream = new FileInputStream(file);
//        this.certData = new byte[(int) file.length()];
//        certStream.read(this.certData);
//        certStream.close();
    }

    public static WXPayConfigImpl getInstance() throws Exception{
        if (INSTANCE == null) {
            synchronized (WXPayConfigImpl.class) {
                if (INSTANCE == null) {
                    INSTANCE = new WXPayConfigImpl();
                }
            }
        }
        return INSTANCE;
    }

    public String getAppID() {
        return "wxf2e44585ce60a754";
    }

    public String getMchID() {
        return "1487915072";
    }

    public String getKey() {
        return "BBf6GwIwlTOiGQTIadrygUmXZZ0NZzdU";
    }

    public InputStream getCertStream() {
        ByteArrayInputStream certBis;
        certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }


    public int getHttpConnectTimeoutMs() {
        return 2000;
    }

    public int getHttpReadTimeoutMs() {
        return 10000;
    }

    public IWXPayDomain getWXPayDomain() {
        return WXPayDomainSimpleImpl.instance();
    }

    public String getPrimaryDomain() {
        return "api.mch.weixin.qq.com";
    }

    public String getAlternateDomain() {
        return "api2.mch.weixin.qq.com";
    }

    @Override
    public int getReportWorkerNum() {
        return 1;
    }

    @Override
    public int getReportBatchSize() {
        return 2;
    }

	@Override
	public String getNotifyUrl() {
		//return "http://8b5b6c97.ngrok.io/pay/payCallBack";
		return "http://www.ele-young.com/pay/payCallBack";
	}

	@Override
	public String getSpbillCreateIp() {
		return "106.14.177.36";
	}
}
